package com.hbnu.iostream;

import java.io.File;
import java.io.IOException;

/**
 * @author kittychen
 * @date 2025-09-30 下午 3:10
 */
public class FileOperator03 {
    public static void main(String[] args) {
        String path = "E:" + File.separator + "2310" + File.separator + "test1.txt";

        File file = new File(path);

        if (file.exists()) {
            boolean deleteResult = file.delete();
            if (deleteResult) {
                System.out.println("删除成功");
            } else {
                System.out.println("删除失败");
            }
        } else {
            try {
                boolean newFileResult = file.createNewFile();
                if (newFileResult) {
                    System.out.println("文件创建成功");
                } else {
                    System.out.println("文件创建失败");
                }
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("文件创建失败（异常情况）");
            }
        }

    }
}
